"""
@Auth: Nasa
@Date: 2022/7/16-11:18
"""
import turtle as t
import time


def fang(x, y, long):
    pen = t.Pen()
    pen.goto(x, y)
    for i in range(4):
        pen.fd(long)
        pen.left(90)


def fang_02(x, y, long, pen=None):
    if pen is None:
        pen = t.Pen()
    pen.up()
    pen.goto(x - long / 2, y - long / 2)
    pen.down()
    for i in range(4):
        pen.fd(long)
        pen.left(90)
    pen.up()
    pen.goto(x, y)
    pen.down()


def fang_03(x, y, long, n, pen=None):
    if n == 0:
        return
    if pen is None:
        # print('pen')
        pen = t.Pen()
    fang_02(x, y, long, pen)
    pen.pencolor('red')
    fang_03(x - long, y, long / 3, n - 1, pen)  # 左
    fang_03(x - long, y + long, long / 3, n - 1, pen)  # 左上
    fang_03(x, y + long, long / 3, n - 1, pen)  # 上
    fang_03(x + long, y + long, long / 3, n - 1, pen)  # 右上
    pen.pencolor('yellow')
    fang_03(x + long, y, long / 3, n - 1, pen)  # 右
    fang_03(x + long, y - long, long / 3, n - 1, pen)  # 右下
    fang_03(x, y - long, long / 3, n - 1, pen)  # 下
    fang_03(x - long, y - long, long / 3, n - 1, pen)  # 左下


if __name__ == '__main__':
    p = t.Pen()
    p.speed(50)
    fang_03(0, 0, 180, 4, p)
    time.sleep(5)
